<?php

$gallery = "gallery/";
$title = $_POST["title"];
$ingredientsInput = $_POST["ingredients"];
$preparation = $_POST["preparation"];
$categoriesInput = $_POST["categories"];
$picture = $_FILES['file'];

if ((!$title) || (!$ingredientsInput) || (!$preparation) || (!$categoriesInput) || (!$picture)) {
	
	header("Location: index.php?page=admin&state=error");
	
}

else {
	
	if ($picture["error"] == 0) {
		$image = $gallery . $picture["name"];
		move_uploaded_file($picture["tmp_name"],$image);
		$recipe["title"] = $title;
		$recipe["preparation"] = $preparation;
		$recipe["image"] = $image;
		$ingredients = explode(",",$ingredientsInput);
		$categories = explode(",",$categoriesInput);
		createRecipe($recipe,$ingredients,$categories);
	
		header("Location: index.php?page=successful");
	}
	else {
		header("Location: index.php?page=admin&state=error");
	}

}


?>